package service.role;

import java.util.List;

import org.json.simple.JSONArray;

import base.entity.Page;
import entity.role.MyResource;
import entity.role.Role;
import entity.role.RoleResource;
import entity.role.UserRole;
import entity.user.User;

public interface IRoleService {

	/**
	 * 增加角色
	 * 
	 * @param role
	 * @return
	 * @throws Exception
	 */
	public Role addRole(Role role) throws Exception;

	/**
	 * 修改角色
	 * 
	 * @param role
	 * @return
	 * @throws Exception
	 */
	public Role updateRole(Role role) throws Exception;

	/**
	 * 删除角色
	 * 
	 * @param id
	 * @throws Exception
	 */
	public void deleteRole(String id) throws Exception;

	/**
	 * 分页查询角色
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	public Page<Role> getRolesByPageAndSize(Integer pageNo, Integer pageSize) throws Exception;

	/**
	 * 根据ID查询角色
	 * 
	 * @return
	 * @throws Exception
	 */
	public Role getRoleById(String id) throws Exception;

	/**
	 * 根据角色ID分页查询角色下的用户数据
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Page<UserRole> getUsersByRoleId(Integer pageNo, Integer pageSize, String id) throws Exception;

	/**
	 * 查询该角色下的所有用户
	 * 
	 * @param role
	 * @return
	 * @throws Exception
	 */
	public List<User> getAllUsersFromUserRole(Role role) throws Exception;

	/**
	 * 增加用户到指定角色
	 * 
	 * @param userRoles
	 * @return
	 * @throws Exception
	 */
	public List<UserRole> addUserToRole(List<UserRole> userRoles) throws Exception;

	/**
	 * 从角色中删除用户
	 * 
	 * @param userRoles
	 * @return
	 * @throws Exception
	 */
	public void deleteUserRoleByIds(List<String> ids) throws Exception;

	/**
	 * 增加受控资源
	 * 
	 * @param resource
	 * @return
	 * @throws Exception
	 */
	public MyResource addResource(MyResource resource) throws Exception;

	/**
	 * 分页受控资源
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	public Page<MyResource> getResourcesByPageAndSize(Integer pageNo, Integer pageSize) throws Exception;

	/**
	 * 根据ID查询资源
	 * 
	 * @return
	 * @throws Exception
	 */
	public MyResource getResourceById(String id) throws Exception;

	/**
	 * 根据资源名称查询资源
	 * 
	 * @return
	 * @throws Exception
	 */
	public MyResource getResourceByName(String name) throws Exception;

	/**
	 * 根据id查询子资源
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public List<MyResource> getResourcesByParentId(String id) throws Exception;

	/**
	 * 根据id查询资源
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public MyResource getResourceId(String id) throws Exception;

	/**
	 * 更新资源
	 * 
	 * @return
	 * @throws Exception
	 */
	public MyResource updateResource(MyResource myResource) throws Exception;

	/**
	 * 更新资源状态
	 * 
	 * @return
	 * @throws Exception
	 */
	public MyResource updateResourceState(String id, Boolean activite) throws Exception;

	/**
	 * 根据ID删除资源
	 * 
	 * @param id
	 * @throws Exception
	 */
	public void deleteResourceById(String id) throws Exception;

	/**
	 * 加载所有父节点为空的资源数据
	 * 
	 * @throws Exception
	 */
	public List<MyResource> getAllParentResource() throws Exception;

	/**
	 * 获取当前结点的子节点树形结构数据
	 * 
	 * @param myResource
	 * @throws Exception
	 * @return
	 */
	public JSONArray geResourceChildren(MyResource myResource) throws Exception;

	/**
	 * 根据用户菜单权限获取当前结点的子节点树形结构数据
	 * 
	 * @param myResource
	 * @throws Exception
	 * @return
	 */
	public JSONArray geResourceChildren(MyResource myResource, List<MyResource> roleResources, Boolean isSuperManager)
			throws Exception;

	/**
	 * 给角色授权
	 * 
	 * @param roleIds
	 * @param resourceIds
	 */
	public void addRoleResource(List<String> roleIds, List<String> resourceIds) throws Exception;

	/**
	 * 根据角色ID查询当前角色已经有的权限
	 * 
	 * @param id
	 * @throws Exception
	 */
	public List<RoleResource> getCurrentRoleResourceByRoleId(String id) throws Exception;

	/**
	 * 删除旧的权限
	 * 
	 * @param resourceIds
	 * @throws Exception
	 */
	public void deleteOldRoleResources(List<String> roleIds) throws Exception;

	/**
	 * 
	 * @param id
	 * @throws Exception
	 */
	public List<MyResource> getUserMenusByUserId(String id, Boolean falg, Boolean isSuperManager) throws Exception;

	/**
	 * 根据用户ID判断当前用户是否是超级管理员
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Boolean isSuperMnager(String id) throws Exception;

	/**
	 * 查询系统所有受控权限
	 * 
	 * @return
	 * @throws Exception
	 */
	public List<MyResource> getAllMyResource() throws Exception;

	/**
	 * 根据用户ID查询用户所有权限
	 * 
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public List<MyResource> getCurrentUserResourcesByUserId(String userId) throws Exception;
}
